<template>
  <div class="dataContainer">
    <el-card style="margin: 40px">
      <div slot="header" class="clearfix" style="display: flex;align-items: center;justify-content: space-between">
        <span style="font-size: 18px;font-weight: bold;flex: 1">家长圈审核</span>
        <el-button type="success" icon="el-icon-search" size="mini" style="margin-right: 20px" @click="search">搜索</el-button>
        <div class="block">
          <span class="demonstration" style="font-weight: bold;margin-right: 20px">默认</span>
          <el-date-picker
            @change="changePicker"
            v-model="value1"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期">
          </el-date-picker>
        </div>
      </div>
      <el-table
        :data="tableData"
        :header-cell-style="{textAlign: 'center',backgroundColor:'##ECEFF0',fontSize:'16px',fontWeight:'bold',color:'#101010'}"
        :cell-style="{ textAlign: 'center' }"
        style="width: 100%">
        <el-table-column
          prop="id"
          label="审核ID">
        </el-table-column>
        <el-table-column
          prop="compassNormalUser.nickName"
          label="发布账号">
        </el-table-column>
        <el-table-column
          prop="diary_type"
          label="类型">
        </el-table-column>
        <el-table-column
          prop="diary_desc"
          show-overflow-tooltip
          label="文字内容">
        </el-table-column>
        <el-table-column
          prop="is_images"
          label="含有图片"
          :formatter="formatImg">
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="发布时间">
        </el-table-column>
        <el-table-column
          label="操作">
          <template slot-scope="scope">
            <el-button type="text" style="color: red" @click="delData(scope.row)">删除</el-button>
            <el-button type="text" style="color: #178FFE" @click="toDetail(scope.row)">详情</el-button>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>

import {
  delCommenData,
  delDiarytData,
  delReportData,
  getAllParentList,
  queryAllParentList
} from '../../../../api/system/compassDataReport'
import {delCompassComment} from "@/api/system/CompassDiary";

export default {
  name: 'index',
  data() {
    return {
      tableData: [],
      value1: [],
      beginDate: "",
      endDate: "",
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        startTime:"",
        endTime:""
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    //封装查询条件
    getQueryParams(){
      if (this.value1!=null&&this.value1.length>0){
        //给查询条件开始时间赋值
        this.queryParams.startTime=this.value1[0]
        //给查询条件结束时间赋值
        this.queryParams.endTime=this.value1[1]
      }else{
        //给查询条件开始时间赋值
        this.queryParams.startTime=""
        //给查询条件结束时间赋值
        this.queryParams.endTime=""
      }
    },
    //判断图片内容
    formatImg: function (row, column, cellValue) {
      if (cellValue === 1) {
        return '是'
      } else if (cellValue === 0) {
        return '否'
      }
    },
    toDetail(row) {
      this.$router.push({
        name: "reportDetail",
        query: {
          diary_type: row.diary_type,
          id: row.id,
          uid:row.u_id
        }
      })
    },
    //获取列表信息
    getList() {
      this.getQueryParams()
      getAllParentList(this.queryParams).then(res => {
        this.tableData = res.rows
        this.total = res.total
      })
    },
    //  搜索选择
    changePicker() {
      this.getQueryParams()
      queryAllParentList(this.queryParams).then(res=>{
        this.tableData = res.rows
        this.total=res.total
      })
    },
    //搜索按钮
    search(){
      queryAllParentList(this.queryParams).then(res=>{
        this.tableData = res.rows
        this.total=res.total
      })
    },
    //  删除
    delData(row) {
      const ids = row.id
      const type = row.diary_type
      if (type === "回复") {
        this.$confirm('是否删除这条数据', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
          delReportData(ids)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        }).catch(function () {
        })
      } else if (type === "评论") {
        this.$confirm('是否删除这条数据', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
           delCommenData(ids)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        }).catch(function () {
        })
      } else if (type === "日记") {
        this.$confirm('是否删除这条数据', '警告', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(function () {
           delDiarytData(ids)
        }).then(() => {
          this.getList()
          this.msgSuccess('删除成功')
        }).catch(function () {
        })
      }

    }
  }
}
</script>

<style scoped>

</style>
